#include "qabstractitemviewhost.h"

#include "../../libs/shared/property/qabstractproperty.h"
#include "../../libs/shared/qpropertyfactory.h"
#include "../../libs/shared/qcommonstruct.h"

#include <QAbstractItemView>

QAbstractItemViewHost::QAbstractItemViewHost(QAbstractHost *parent):
    QAbstractScrollAreaHost(parent)
{
}

void QAbstractItemViewHost::init_property()
{
    QAbstractScrollAreaHost::init_property();

    QAbstractProperty* pro;

    pro=QPropertyFactory::create_property("Bool");
    if(pro!=NULL)
    {
        pro->set_property("name","alternatingRowColors");
        pro->set_attribute("show_name",tr("Alternating Row Colors"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Enum");
    if(pro!=NULL)
    {
        pro->set_property("name","selectionBehavior");
        pro->set_attribute("show_name",tr("Selection Behavior"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        ComboItems items;
        tagComboItem item;

        item.m_text=tr("Select Items");
        item.m_value=QAbstractItemView::SelectItems;
        items.append(item);

        item.m_text=tr("Select Rows");
        item.m_value=QAbstractItemView::SelectRows;
        items.append(item);

        item.m_text=tr("Select Columns");
        item.m_value=QAbstractItemView::SelectColumns;
        items.append(item);

        pro->set_attribute("items",QVariant::fromValue<ComboItems>(items));
        insert_property(pro);
    }

    pro=QPropertyFactory::create_property("Enum");
    if(pro!=NULL)
    {
        pro->set_property("name","selectionMode");
        pro->set_attribute("show_name",tr("selection Mode"));
        pro->set_attribute("group","Attributes");
        pro->set_attribute(ATTR_CAN_SAME,true);
        ComboItems items;
        tagComboItem item;

        item.m_text=tr("Single Selection");
        item.m_value=QAbstractItemView::SingleSelection;
        items.append(item);

        item.m_text=tr("Contiguous Selection");
        item.m_value=QAbstractItemView::ContiguousSelection;
        items.append(item);

        item.m_text=tr("Extended Selection");
        item.m_value=QAbstractItemView::ExtendedSelection;
        items.append(item);

        item.m_text=tr("Multi Selection");
        item.m_value=QAbstractItemView::MultiSelection;
        items.append(item);

        item.m_text=tr("NoSelection");
        item.m_value=QAbstractItemView::NoSelection;
        items.append(item);

        pro->set_attribute("items",QVariant::fromValue<ComboItems>(items));
        insert_property(pro);
    }
}

void QAbstractItemViewHost::setAlternatingRowColors(bool alternatingRowColors)
{
    set_property_value("alternatingRowColors",alternatingRowColors);
}

bool QAbstractItemViewHost::alternatingRowColors()
{
    return get_property_value("alternatingRowColors").toBool();
}

void QAbstractItemViewHost::setSelectionBehavior(int selectionBehavior)
{
    set_property_value("selectionBehavior",selectionBehavior);
}

int QAbstractItemViewHost::selectionBehavior()
{
    return get_property_value("selectionBehavior").toInt();
}

void QAbstractItemViewHost::setSelectionMode(int selectionMode)
{
    set_property_value("selectionMode",selectionMode);
}

int QAbstractItemViewHost::selectionMode()
{
    return get_property_value("selectionMode").toInt();
}
